from typing import Union
from datetime import date, datetime

from fastapi import Query
from pydantic import BaseModel, Field

from like.schema_base import EmptyStrToNone


class {{{ entity_name }}}ListIn(BaseModel):
    """{{{ function_name }}}列表参数"""
    {%- for column in columns %}
    {%- if column.is_query %}
    {{{ column.column_name }}}: Union[{{{ column.java_type }}}, None{% if column.java_type!='str' %}, EmptyStrToNone{% endif %}] = Field(default=None, title='{{{ column.column_comment }}}'{% if column.java_field != column.column_name%},alias='{{{column.column_name}}}'{% endif %})
    {%- endif %}
    {%- endfor %}

    class Config:
        from_attributes = True
        
        field_operator_mapping = {
            {%- for column in columns %}
            {%- if column.is_query %}
            {%- set query_opr = model_opr_map.get(column.query_type) or column.query_type %}
            '{{{ column.java_field }}}': '{{{query_opr}}}',
            {%- endif %}
            {%- endfor %}
        }


class {{{ entity_name }}}DetailIn(BaseModel):
    """{{{ function_name }}}详情参数"""
    {%- for column in columns %}
    {%- if column.is_pk %}
    {{{ column.column_name }}}: {% if column.is_required %}{{{ column.java_type }}}{% else %}Union[{{{ column.java_type }}}, None]{% endif %} = Query(title='{{{ column.column_comment }}}'{% if column.java_type=='int' %},gt=0{% endif %})
    {%- endif %}
    {%- endfor %}


class {{{ entity_name }}}AddIn(BaseModel):
    """{{{ function_name }}}新增参数"""
    {%- for column in columns %}
    {%- if column.is_insert %}
    {{{ column.column_name }}}: {% if column.is_required %}{{{ column.java_type }}}{% else %}Union[{{{ column.java_type }}}, None]{% endif %} = Field({% if not column.is_required %}default=None,{% endif %}title='{{{ column.column_comment }}}'{% if column.java_field != column.column_name%},alias='{{{column.column_name}}}'{% endif %})
    {%- endif %}
    {%- endfor %}


class {{{ entity_name }}}EditIn(BaseModel):
    """{{{ function_name }}}编辑参数"""
    {%- for column in columns %}
    {%- if column.is_edit %}
    {{{ column.column_name }}}: {% if column.is_required %}{{{ column.java_type }}}{% else %}Union[{{{ column.java_type }}}, None]{% endif %} = Field({% if not column.is_required %}default=None,{% endif %}title='{{{ column.column_comment }}}'{% if column.java_type=='int' %},gt=0{% endif %}{% if column.java_field != column.column_name%},alias='{{{column.java_field}}}'{% endif %})
    {%- endif %}
    {%- endfor %}


class {{{ entity_name }}}DelIn(BaseModel):
    """{{{ function_name }}}删除参数"""
    {%- for column in columns %}
    {%- if column.is_pk %}
    {{{ column.column_name }}}: {{{ column.java_type }}} = Field(title='{{{ column.column_comment }}}'{% if column.java_type=='int' %},gt=0{% endif %})
    {%- endif %}
    {%- endfor %}


class {{{ entity_name }}}Out(BaseModel):
    """{{{ function_name }}}返回信息"""
    {%- for column in columns %}
    {%- if column.is_list or column.is_pk %}
    {{{ column.java_field }}}: {% if column.is_required %}{{{ column.java_type }}}{% else %}Union[{{{ column.java_type }}}, None]{% endif %} = Field({% if not column.is_required %}default=None,{% endif %}title='{{{ column.column_comment }}}'{% if column.java_field != column.column_name%},alias='{{{column.column_name}}}'{% endif %})
    {%- endif %}
    {%- endfor %}
    {%- if table.gen_tpl == 'tree' %}
    children: Union['{{{ entity_name }}}Out', None] = Field(title='子集')
    {%- endif %}

    class Config:
        from_attributes = True

{% if table.is_basic_data %}
class {{{ entity_name }}}OutAll(BaseModel):
    """{{{ function_name }}}所有信息"""
    {%- for column in columns %}
    {%- if column.is_list or column.is_pk %}
    {{{ column.java_field }}}: {% if column.is_required %}{{{ column.java_type }}}{% else %}Union[{{{ column.java_type }}}, None]{% endif %} = Field({% if not column.is_required %}default=None,{% endif %}title='{{{ column.column_comment }}}'{% if column.java_field != column.column_name%},alias='{{{column.column_name}}}'{% endif %})
    {%- endif %}
    {%- endfor %}

    class Config:
        from_attributes = True
{% endif %}
